/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package generatorGraphics.graphics;

import java.util.ArrayList;
import org.jfree.chart.ChartPanel;
import softwareControl.SearchCommands;

/**
 *
 * @author Heitor
 */
public class Graph {
    
    protected SearchCommands search;
    
    protected String name;
    protected String help;
        
    protected ChartPanel chartPanel;
    protected ArrayList<String> unitList;
    protected ArrayList<ArrayList<String>> optionsList;
    protected String unitActive;
    
    protected ArrayList<Object> answer;
    protected ArrayList<String> commands;
    
    protected Boolean isFilter;
    protected Object parameterFilter;
    
    public Graph(){
    
        unitList = new ArrayList<>();
        optionsList = new ArrayList<>();
        commands = new ArrayList<>();
        parameterFilter = new ArrayList<>();
        
        isFilter = false;
        
    }
    
    public void start(String directory){
        if(directory == null || directory.equals("")){
            search = new SearchCommands(commands);
        } else{
            search = new SearchCommands(directory, commands);
        }
        
        answer = (ArrayList<Object>) search.getCommandsAnswer();
    }
    
    public boolean isNumber(String texto){
        if(texto == null || texto.equals("")) {
            return false;
        }  
        for (char letra : texto.toCharArray()) {
            if((letra < '0' || letra > '9') && (letra != '.')) {
                return false;
            }
        }  
        return true; 
    }
    
    protected void createGraph(String unit){
    
    }
    
    @Override
    public String toString(){
        return name;
    }

    public String getName() {
        return name;
    }

    public ArrayList<String> getUnitList() {
        return unitList;
    }

    public ChartPanel getChartPanel() {
        if(search != null){
            return chartPanel;
        } else {
            return new ChartPanel(null);
        }
    }

    public String getHelp() {
        return help;
    }

    public ChartPanel getChartPanel(String unit) {
        if(search != null){
            for(int i=0; i<unitList.size(); i++){
                if(unit.equals(unitList.get(i))){
                    createGraph(unit);
                }
            }
            return chartPanel;
        } else {
            return new ChartPanel(null);
        }
        
    }

    public ArrayList<String> getOptionsList(String unit) {
        ArrayList<String> auxReturn = new ArrayList<>();
        
        for(int i=0; i<optionsList.size(); i++){
            if((optionsList.get(i)).get(0).equals("[UNIT]" + unit)){
                
                for(int j=1; j<optionsList.get(i).size(); j++){
                    auxReturn.add(optionsList.get(i).get(j));
                }
            }
        }
        return auxReturn;
    }
    
    public Object getFilter(String unit){
        parameterFilter = new ArrayList<>();
        
        return parameterFilter;
    }
    
    public ChartPanel filtrate(String unit, Object parameterFiltrate){
        
        return new ChartPanel(null);
    }

    /**
     * @return the isFilter
     */
    public Boolean getIsFilter() {
        return isFilter;
    }

    /**
     * @param isFilter the isFilter to set
     */
    public void setIsFilter(Boolean isFilter) {
        this.isFilter = isFilter;
    }
    
}
